using System;
using System.IO;

namespace Graphe.Data
{
    public class ManuscriptImageProvider
    {
        #region Singleton

        private static ManuscriptImageProvider _instance;

        public static ManuscriptImageProvider Instance
        {
            get
            {
                if (_instance == null)
                    _instance = new ManuscriptImageProvider();

                return _instance;
            }
        }

        #endregion

        /// <summary>
        /// Gets all the images for a given directory.
        /// </summary>
        /// <param name="directoryName">The directory to search for images.</param>
        /// <returns>Collection of ManuscriptImage objects.</returns>
        public DocumentImageCollection GetImages(string directoryName)
        {
            DocumentImageCollection images = new DocumentImageCollection();

            System.Collections.Generic.SortedDictionary<string, string> sortedFiles = new System.Collections.Generic.SortedDictionary<string, string>();

            string[] fileNames = Directory.GetFiles(directoryName);
            foreach (string str in fileNames)
            {
                FileInfo fi = new FileInfo(str);
                
                if(fi.Extension == ".jpg")
                {
                    sortedFiles.Add(str, str);
                }
            }

            foreach (string key in sortedFiles.Keys)
            {
                DocumentImage image = new DocumentImage(key);
                images.Add(image);
            }

            return images;
        }


    }
}
